package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.GroupCompany;
import sjtu.ist.warehouse4ws.service.GroupCompanyService;
import sjtu.ist.warehouse4ws.vo.FullGroupCompanyVO;

import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;

public class GroupCompanyAction  extends CopyTableAction  {
	
	//private List<GroupCompany> groupCompanyList = new ArrayList<GroupCompany>();
	private List<FullGroupCompanyVO> groupCompanyList = new ArrayList<FullGroupCompanyVO>();
	private GroupCompanyService groupCompanyService;
	private boolean success;
	private String message;
	private Integer id;
	private Integer status;
	
	private String groupCompanyName;
	
	
	public String getGroupCompanyName() {
		return groupCompanyName;
	}

	public void setGroupCompanyName(String groupCompanyName) {
		this.groupCompanyName = groupCompanyName;
	}

	
	
	@JSON(name = "totalGroupCompany")
	public int getTotalGroupCompanyList() {
		return this.groupCompanyList.size();
	}
	
	@JSON(name = "groupCompanyList")
	public List<FullGroupCompanyVO> getGroupCompanyList() {
		return groupCompanyList;
	}

	public void setGroupCompanyService(GroupCompanyService groupCompanyService) {
		this.groupCompanyService = groupCompanyService;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@JSON(name = "message")
	public String getMessage() {
		return message;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@JSON(name = "success")
	public boolean isSuccess() {
		return success;
	}
	
	//@JSON(name = "companyUser")
	public String showGroupCompanyList(){
		List<GroupCompany> templist=groupCompanyService.getGroupCompanyList();
	
		for(GroupCompany e : templist){
			
			groupCompanyList.add(groupCompanyService.getFullGroupCompany(e));
		}
		success = true;
		return SUCCESS;
	}
	
	public String updateGroupCompany(){
		GroupCompany gc=groupCompanyService.get(id);
		gc.setStatus(status);
		groupCompanyService.update(gc);
		if(status==2){
			this.copyAll(gc.getGroupId(), gc.getCompanyId().toString());
		}
		success = true;
		return SUCCESS;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}


}
